﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace HartConfigTool.UI.ExpandControls
{
    public class GridViewUpdater : IObserver
    {
        private readonly DataGridView _dataGridView;

        public GridViewUpdater(DataGridView dataGridView)
        {
            _dataGridView = dataGridView;
        }
        public void Update(List<string> listStr)
        {
            if (_dataGridView.InvokeRequired)
            {
                _dataGridView.Invoke(new Action(() =>
                {
                    for (int i = 0; i < listStr.Count; i++)
                    {
                        _dataGridView.Rows[i].Cells[1].Value = listStr[i];
                    }
                }));
            }
            else
            {
                for (int i = 0; i < listStr.Count; i++)
                {
                    _dataGridView.Rows[i].Cells[1].Value = listStr[i];
                }
            }
        }
    }
}
